package com.woniu.supermarket.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.supermarket.entity.Stock;
import com.woniu.supermarket.mapper.StockMapper;
import com.woniu.supermarket.service.IStockService;
import com.woniu.supermarket.vo.StockVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StockServiceImpl implements IStockService {
    @Autowired
    StockMapper stockMapper;
    @Override
    public PageInfo<StockVo> findStockByCons(Integer now, Integer size, String name) {
        PageHelper.startPage(now,size);
        List<StockVo> stlist = stockMapper.selectByName(name);
        return new PageInfo<>(stlist);
    }

    @Override
    public int modifyStockLimit(Stock stock) {
        return stockMapper.updateStockLimit(stock);
    }

    @Override
    public int removeStock(Integer id) {
        return stockMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<StockVo> findStock(Integer now, Integer size) {
        PageHelper.startPage(now,size);
        List<StockVo> lists = stockMapper.selectStock();
        return new PageInfo<>(lists);
    }

}
